﻿using MedicalManagementAPP.MyException;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MedicalManagementAPP.Forms
{
    public partial class RegForm : Form
    {
        LoginForm loginForm;
        public RegForm(LoginForm fatherForm)
        {
            this.loginForm = fatherForm;
            InitializeComponent();
            skinEngine1.SkinFile = @"irisskin2\Wave.ssk";
        }

        private void RegForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            loginForm.Show();
        }

        private void exitButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void regButton_Click(object sender, EventArgs e)
        {
            string name = nameTextBox.Text;
            string psw = pswTextBox.Text;
            string phone = phoneTextBox.Text;

            if (name == "" | psw == "" | phone == "")
            {
                MessageBox.Show("请输入所有的项目");
                return;
            }
            if (psw != pswTextBox2.Text)
            {
                MessageBox.Show("输入的两次密码不一致");
                ClearTextBoxes();
                return;
            }
            bool flag=false;
            try
            {
                flag = AccountManager.PatientReg(name, psw, phone);
            }catch(PersonExist)
            {
                MessageBox.Show("用户已经存在了，请更换手机号");
                ClearTextBoxes();
                return;
            }
            catch (WrongPhone)
            {
                MessageBox.Show("请输入正确的电话号码\n电话号码是您登陆的凭证");
                ClearTextBoxes();
                return;
            }
            
            if (flag)
            {
                MessageBox.Show("注册成功，现在您可以回到主界面登录了");
                ClearTextBoxes();
                return;
            }
            else
            {
                MessageBox.Show("注册失败");
                ClearTextBoxes();
                return;
            }
        }
        private void ClearTextBoxes()
        {
            nameTextBox.Text = "";
            phoneTextBox.Text = "";
            pswTextBox.Text = "";
            pswTextBox2.Text = "";
        }
    }
}
